from tool.data_processing import DataProcessing

class SendStructure(object):

    def __init__(self, devices, command, signal, total, position, data):
        self.message_head = "AA33"
        self.devices = self.set_devices(devices)  # 模块
        self.Command = self.set_command(command)  # 命令码
        self.Signal = self.set_signal(signal)  # 标志位
        self.Total = self.set_total(total)  # 总包数
        self.Position = self.set_position(position)  # 当前包
        self.data = self.set_data(data)  # 数据域
        self.Length = self.set_length()  # 长度
        self.check = "25"  # 校验位

    @staticmethod
    @DataProcessing.limit_str_bit_size(1)
    def set_devices(data) -> str:  # 校验模块长度
        return data

    @staticmethod
    @DataProcessing.limit_str_bit_size(1)
    def set_command(data) -> str:  # 校验命令码长度
        return data

    def set_length(self) -> str:  # 计算从模块-数据域的所有值长度
        return DataProcessing.sum_str_size(
            self.message_head, self.devices, self.Command, self.Signal, self.Total, self.Position, self.data)

    @staticmethod
    @DataProcessing.limit_str_bit_size(1)
    def set_signal(data) -> str:  # 校验标志位长度
        return data

    @staticmethod
    @DataProcessing.limit_str_bit_size(2)
    def set_total(data) -> str:  # 校验总包数长度
        return data

    @staticmethod
    @DataProcessing.limit_str_bit_size(2)
    def set_position(data) -> str:  # 校验当前包数长度
        return data

    @staticmethod
    def set_data(data) -> str:
        return data

    def get_send_data(self) -> str:
        send_data = self.message_head + self.devices + self.Command + self.Length + self.Signal + self.Total \
                    + self.Position + self.data + self.check
        return send_data.lower()


if __name__ == '__main__':
    a = SendStructure(
        devices="01", command="01", signal="01", total="0001", position="0001", data="")
    print(a.get_send_data())
'''
AA3301010009010001000125
aa3301010009010001000108
'''
